﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MapWindow.Components;
using MapWindow.Data;
using MapWindow.Drawing;
using MapWindow.Geometries;
using MapWindow.Map;
using MapWindow.Plugins;

namespace HydroAnalyzer
{
    [MapWindowPlugin("HydroAnalyzer", Author = "ISU", UniqueName = "mw_HydroAnalyzer_1", Version = "1")]
    public class Main : Extension, IMapPlugin
    {
        #region Variables

        //reference to the main application and it's UI items
        private IMapPluginArgs _mapArgs;

        /*//the main tab control where map view, graph view and table view are displayed
        private TabControl _mainTabControl = null;

        //the tab page which will be added to the tab control by the plugin
        private TabPage _tabPage = null;*/

        //a sample toolbar button added by the plugin
        private ToolStripButton btnSamplePlugin = null;

        //a sample menu item added by the plugin
        private ToolStripMenuItem mnuSamplePlugin = null;

        #endregion

        #region IExtension Members

        /// <summary>
        /// Fires when the plugin should become inactive
        /// </summary>
        protected override void OnDeactivate()
        {
            if (_mapArgs.MainToolStrip != null && btnSamplePlugin != null)
            {
                _mapArgs.MainToolStrip.Items.Remove(btnSamplePlugin);
            }
            if (_mapArgs.MainMenu != null && mnuSamplePlugin != null)
            {
                _mapArgs.MainMenu.Items.Remove(mnuSamplePlugin);
            }

            /*if (_mainTabControl != null && _tabPage != null)
            {
                _mainTabControl.TabPages.Remove(_tabPage);
            }*/
        }

        #endregion


        #region IPlugin Members

        /// <summary>
        /// Initialize the mapWindow 6 plugin
        /// </summary>
        /// <param name="args">The plugin arguments to access the main application</param>
        public void Initialize(IMapPluginArgs args)
        {
            _mapArgs = args;

            btnSamplePlugin = new ToolStripButton();

            // Add UI features
            btnSamplePlugin.DisplayStyle = ToolStripItemDisplayStyle.Text;
            //btnSamplePlugin.Image = Resources.MySampleIcon1.ToBitmap();
            btnSamplePlugin.Name = "btnHydroAnalyzer";
            btnSamplePlugin.ToolTipText = "HydroAnalyzer";
            btnSamplePlugin.Click += new EventHandler(btnSamplePlugin_Click);

            if (_mapArgs.ToolStripContainer != null)
            {
                // Add the 'Sample Plugin' button
                _mapArgs.MainToolStrip.Items.Add(btnSamplePlugin);

                /*// Add the 'Added by plugin' tab control
                foreach (Control control in _mapArgs.ToolStripContainer.ContentPanel.Controls)
                {
                    if (control is TabControl)
                    {
                        _mainTabControl = control as TabControl;
                        _tabPage = new TabPage("Tab added by plugin");
                        _mainTabControl.TabPages.Add(_tabPage);
                        break;
                    }
                }*/
            }

            /*//add some items to the newly created tab control
            if (_tabPage != null)
            {
                Label lbl = new Label();
                lbl.AutoSize = true;
                lbl.Text = "This tab was added by the HydroAnalyzer Plugin.";
                lbl.Location = new System.Drawing.Point(_tabPage.Width / 2, _tabPage.Height / 2);
                _tabPage.Controls.Add(lbl);
            }*/

            //to add the menu
            mnuSamplePlugin = new ToolStripMenuItem("HydroAnalyzer");
            ToolStripMenuItem mnuSearch1 = new ToolStripMenuItem("HydroAnalyzer Cube");
            ToolStripMenuItem mnuSearch2 = new ToolStripMenuItem("HydroAnalyzer OLAP");
            mnuSamplePlugin.DropDownItems.Add(mnuSearch1);
            mnuSamplePlugin.DropDownItems.Add(mnuSearch2);
            if (_mapArgs.MainMenu != null)
            {
                _mapArgs.MainMenu.Items.Add(mnuSamplePlugin);
                mnuSearch2.Click += new EventHandler(btnSamplePlugin_Click);
            }
        }

        #endregion

        #region Event Handlers

        void btnSamplePlugin_Click(object sender, EventArgs e)
        {
            //frmCreateNewCube frm = new frmCreateNewCube();
            //if (frm.ShowDialog() == DialogResult.OK)
            //{
            //    frmEnterQuery myForm = new frmEnterQuery();
            //    myForm.Show();
            //}
            frmMain f = new frmMain();
            f.Show();
        }

        #endregion
    }
}
